//
//  ClassificationViewController.m
//  Preject_B
//
//  Created by lanou on 15/12/16.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "ClassificationViewController.h"
#import "GiftCollectionViewController.h"
#import "StrategyCollectionViewController.h"
@interface ClassificationViewController ()
@property (nonatomic,retain,readonly) GiftCollectionViewController *giftCollectionVC;
@property (nonatomic,retain,readonly) StrategyCollectionViewController *strategyCollectionVC;

@end

@implementation ClassificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _strategyCollectionVC = [[StrategyCollectionViewController alloc] initWithCollectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
    
    // 2. 添加礼物模块
    _giftCollectionVC = [[GiftCollectionViewController alloc] initWithCollectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
    
    [self.view addSubview:_strategyCollectionVC.view];
    [self addChildViewController:_strategyCollectionVC];
    
    
    
    UISegmentedControl *segCtr = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"攻略",@"礼物",nil]];
    segCtr.tintColor = [UIColor whiteColor];
    [segCtr addTarget:self action:@selector(changeValueAction:) forControlEvents:UIControlEventValueChanged];
    segCtr.selectedSegmentIndex = 0;
    self.navigationItem.titleView = segCtr;
    
    // Do any additional setup after loading the view.
}

//分段空间触发方法
- (void)changeValueAction:(UISegmentedControl *)segmentedControl
{
    //判断当前选中空间的下标
    switch (segmentedControl.selectedSegmentIndex) {
        case 0:
            // 1. 移除礼物模块
            [_giftCollectionVC.view removeFromSuperview];
            [_giftCollectionVC removeFromParentViewController];

            // 2. 添加攻略模块
            [self.view addSubview:_strategyCollectionVC.view];
            [self addChildViewController:_strategyCollectionVC];
            [self.view sendSubviewToBack:_strategyCollectionVC.view];
            break;
        case 1:
            // 1. 移除攻略模块
            [_strategyCollectionVC.view removeFromSuperview];
            [_strategyCollectionVC removeFromParentViewController];
            
            
            [self.view addSubview:_giftCollectionVC.view];
            [self addChildViewController:_giftCollectionVC];
            [self.view sendSubviewToBack:_giftCollectionVC.view];
            
            break;
            
        default:
            break;
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
